package com.maple.hello.controller;

import com.maple.common.ResultBean;
import com.maple.common.ResultUtil;
import com.maple.model.Student;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * author: HuaZhe Ray
 * <p>
 * describe: HelloController
 * <p>
 * createDate: 2017/12/14
 * createTime: 18:09
 */
//@RestController
public class HelloController {

    @GetMapping("/hello")
    public String hello(){
        return "Hello World!!!";
    }


    @GetMapping
    public String index(){
        return "Index";
    }

    @PostMapping(value = "/students")
    public ResultBean<Student> girlAdd(@Valid Student stu, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            return ResultUtil.error(1, bindingResult.getFieldError().getDefaultMessage());
        }
        return null;
    }
}
